//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.pc.admin.util;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;


public class DateFormatUtil {
    public DateFormatUtil() {
    }

    public static Date getTodayStartTime(Date date) throws ParseException {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
        String startTime = formatter.format(date);
        return formatter.parse(startTime);
    }

    public static Date getTodayEndTime(Date date) {
        String endTime = DateFormatUtils.format(date, "yyyy-MM-dd 23:59:59");
        return getDateTime(endTime);
    }

    public static Date getDateFormat(String dateString) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");

        try {
            return formatter.parse(dateString);
        } catch (ParseException var3) {
            var3.printStackTrace();
            return null;
        }
    }

    public static Date getDate(String dateString) {
        if (StringUtils.isEmpty(dateString)) {
            return null;
        } else {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

            try {
                return formatter.parse(dateString);
            } catch (ParseException var3) {
                return null;
            }
        }
    }

    public static Date getDateTime(String dateString) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        try {
            return formatter.parse(dateString);
        } catch (ParseException var3) {
            var3.printStackTrace();
            return null;
        }
    }

    public static LocalDateTime getLocalDateTimeFormat(String dateString) {
        try {
            DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
            LocalDateTime ldt = LocalDateTime.parse(dateString, df);
            return ldt;
        } catch (Exception var3) {
            var3.printStackTrace();
            return null;
        }
    }

    public static String getDateTimeFormat(Date date) {
        try {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String ldt = df.format(date);
            return ldt;
        } catch (Exception var3) {
            return null;
        }
    }

    public static String getNowDateTime() {
        try {
            SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
            String ldt = df.format(new Date());
            return ldt;
        } catch (Exception var2) {
            return null;
        }
    }

    public static String getNowDate() {
        try {
            SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
            String ldt = df.format(new Date());
            return ldt;
        } catch (Exception var2) {
            return null;
        }
    }

    public static String getDateFormat(Date date) {
        try {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            String ldt = df.format(date);
            return ldt;
        } catch (Exception var3) {
            var3.printStackTrace();
            return null;
        }
    }

    public static String addDate(String dateStr, int day) {
        try {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            Date date = df.parse(dateStr);
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            cal.add(6, day);
            return df.format(cal.getTime());
        } catch (Exception var5) {
            var5.printStackTrace();
            return null;
        }
    }

    public static Date addDate(Date date, int day) {
        return addDate(date, day);
    }

    public static Date getTodayStartTime() {
        return getStartTime(LocalDate.now());
    }

    public static Date getPrevDayStartTime() {
        return getStartTime(LocalDate.now().minusDays(1L));
    }

    private static Date getStartTime(LocalDate localDate) {
        return Date.from(LocalDateTime.of(localDate, LocalTime.MIN).atZone(ZoneId.systemDefault()).toInstant());
    }

    public static boolean isValidDate(String dateStr) {
        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        sdf.setLenient(false);

        try {
            sdf.parse(dateStr);
            return true;
        } catch (Exception var3) {
            return false;
        }
    }

    public static Date getLastDayOfMonth(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(5, 1);
        cal.roll(5, -1);
        cal.set(10, 23);
        cal.set(12, 59);
        cal.set(13, 59);
        return cal.getTime();
    }
}